package com.clive.service;

import com.clive.bean.Dishes;
import com.clive.dao.DishesDao;
import com.clive.dao.DishesDaoImpl;
import com.clive.vo.DishesVo;

import java.util.Date;
import java.util.List;

public class DishesServiceImpl implements DishesService {
    private DishesDao dishesDao = new DishesDaoImpl();
    @Override
    public boolean addDishes(Dishes dishes) {
        Date date = new Date();
        dishes.setBuyconut(0);
        dishes.setCreated(date);
        dishes.setUpdated(date);
        dishes.setStatus(1);
        dishes.setPicpath("fwafe.jpg");
        int i = dishesDao.addDishes(dishes);
        if(i<=0){
            return false;
        }
        return true;

    }

    @Override
    public boolean updateDishesById(Dishes dishes) {
        Date date = new Date();
        dishes.setUpdated(date);
        int i = dishesDao.updateDishes(dishes);
        if(i<=0){
            return false;
        }
        return true;
    }

    @Override
    public boolean deleteDishesById(Integer dishesId) {
        int i = dishesDao.deleteDishesById(dishesId);
        if(i<=0){
            return false;
        }
        return true;

    }
    public boolean deleteDishesByIds(List<Integer> ids) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public DishesVo findDishesByCurrentPage(Integer currentPage, Integer limit) {
        DishesVo vo = new DishesVo();
        int dishesTotal = dishesDao.findDIshesByCount();
        vo.setDishestotal(dishesTotal);
        List<Dishes> list = dishesDao.findDishesByCurrentPage((currentPage-1)*limit, limit);
        vo.setDishess(list);
        return vo;

    }

    @Override
    public List<Dishes> findDishesByName(String dishName) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public List<Dishes> findDishesByCategoryId(Integer dishesCategoryId) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Dishes findDishesById(Integer dishId) {
        Dishes dishes = dishesDao.findDishesById(dishId);
        return dishes;
    }

}
